package com.jk.myimkit.imkit.widget.provide;

import android.net.Uri;

import com.jk.myimkit.imkit.RongContext;
import com.jk.myimkit.imkit.model.ConversationKey;
import com.jk.myimkit.imkit.model.ConversationProviderTag;
import com.jk.myimkit.imkit.model.UIConversation;

import io.rong.imlib.model.Conversation;
import io.rong.imlib.model.PublicServiceProfile;

@ConversationProviderTag(
        conversationType = "app_public_service",
        portraitPosition = 1
)
public class AppServiceConversationProvider extends PrivateConversationProvider implements IContainerItemProvider.ConversationProvider<UIConversation> {
    public AppServiceConversationProvider() {
    }

    public String getTitle(String id) {
        ConversationKey mKey = ConversationKey.obtain(id, Conversation.ConversationType.APP_PUBLIC_SERVICE);
        PublicServiceProfile info = RongContext.getInstance().getPublicServiceInfoFromCache(mKey.getKey());
        String name;
        if (info != null) {
            name = info.getName();
        } else {
            name = "";
        }

        return name;
    }

    public Uri getPortraitUri(String id) {
        ConversationKey mKey = ConversationKey.obtain(id, Conversation.ConversationType.APP_PUBLIC_SERVICE);
        PublicServiceProfile info = RongContext.getInstance().getPublicServiceInfoFromCache(mKey.getKey());
        Uri uri;
        if (info != null) {
            uri = info.getPortraitUri();
        } else {
            uri = null;
        }

        return uri;
    }
}

